package demo4;

import java.util.Objects;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: xiaotutu
 * Date: 2023-11-30
 * Time: 14:50
 */

class Student {
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    /*public boolean equals(Student o) {
        *//*if(this.name.equals(o.name)) {
            return true;
        }else {
            return false;
        }*//*
        if(this.age == o.age) {
            return true;
        }else {
            return false;
        }
    }*/

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return age == student.age && Objects.equals(name, student.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }
}

public class Test {
    public static void main(String[] args) {
        Student student1 = new Student("xiaohua",10);
        Student student2 = new Student("xiaohua",10);
        System.out.println(student1 == student2);
        System.out.println(student1.equals(student2));

    }
}
